package io.hilo.example.account.service;

import org.jretty.apibase.Request;
import org.jretty.apibase.Result;
import org.jretty.util.NestedRuntimeException;

import org.hilo.boot.core.BaseMsg;
import org.hilo.boot.core.exception.AppException;
import io.hilo.example.account.api.SimpleService;
import io.hilo.example.account.dto.simple.AddNumberReq;

/**
 * 
 * @author zollty
 * @since 2018年2月24日
 */
@com.alibaba.dubbo.config.annotation.Service
public class SimpleServiceImpl implements SimpleService {
    
    @Override
    public Result<Integer> addNumber(Request<AddNumberReq> req) {
        Integer a = req.getData().getA();
        Integer b = req.getData().getB();
        System.err.printf("方法add被调用 %s+%s", a, b);
        if (a > 1) {
            testMethod(a, b);
        } else {
            System.err.println(a / b);
        }
        if (b < 1) {
            throw new AppException(BaseMsg.PARAM_INVALID, "b=" + b);
        }
        return Result.success(a + b);
    }

    void testMethod(int a, int b) {
        try {
            System.err.println(a / b);
        } catch (Exception e) {
            throw new NestedRuntimeException(e);
        }
    }

}
